/**
 *
 */

var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url: app.setting.att_url,
		pagedata:[],
		action: '',
		pcd: ['广东省', '广州市', '海珠区'],
		birth:'',
		pagetitle:'会员资料',
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth)
	},
	onReady: function (){
		var the = this
	},
	onShow: function (){
		var ssid=wx.getStorageSync('ssid');
		if(!ssid && !app.issession){
			app.util.session();
		}
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (options){
		var the =this
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		the.getpagedata();
	},
	getpagedata: function (){
		var the=this;
		app.util.get(app.access,function(pagedata){
			//console.log('set');console.log(pagedata);
			pagedata.item=pagedata.item?pagedata.item:{}
			pagedata.item.pcd[0]=pagedata.item.pcd.province;
			pagedata.item.pcd[1]=pagedata.item.pcd.city;
			pagedata.item.pcd[2]=pagedata.item.pcd.district;
			the.setData({
				pagedata:pagedata,
				birth:pagedata.item.birth.year+'-'+pagedata.item.birth.month+'-'+pagedata.item.birth.day,
				pcd:pagedata.item.pcd,
				pluginnav:app.session.menus,
				action:app.access.plugin+'/'+app.access.action+'/',
			});
		});
	},
	mobile_code:function(e){
		var the = this
		var pagedata = the.data.pagedata
		var mobile_code_sending=the.data.mobile_code_sending;
		if(!pagedata.item.mobile){
			app.util.msg('请输入手机号','error');
			return false;
		}
		if(mobile_code_sending){
			return false;
		}
		the.setData({
			mobile_code_sending:true
		});
		app.util.showLoading('获取中...');
		app.util.post('core/tools.sms_code/send',{'mobile':pagedata.item.mobile},function(res){
			app.util.hideLoading();
			if(res=='success'){
					var sys_second = 60;
					var btntitle=''
					app.countInterval = setInterval(() => {
						sys_second -= 1;
						btntitle=sys_second+'秒后重试';
						the.setData({
							btntitle : btntitle
						});
						if (sys_second <= 0){
							clearInterval(app.countInterval);
							the.setData({
								btntitle : '重新发送',
								mobile_code_sending:false
							});
						}
					}, 1000);
			}else{
				the.setData({
					mobile_code_sending:false
				});
				app.util.msg('验证码发送失败!','error');
			}
		});
	},
	info_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户信息
		var the=this;
		app.util.getUserInfo(e,function(res){
			the.getpagedata();
		});
		the.setData({
			ShowAuthM:false
		})
	},
	mobile_login:function(e){
		var the=this
		var pagedata=the.data.pagedata
		//根据openid为用户登陆，此处尝试获取用户手机号
		app.util.post('core/member.set/setmobile/',e.detail,function(res){
			//console.log(res);
			pagedata.item.mobile=res.mobile
			the.setData({
				'pagedata.item':pagedata.item
			})
		});
	},
	 bindRegionChange: function (e) {
		//console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
		  pcd: e.detail.value
		})
	  },
	 bindDateChange: function(e) {
		//console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
		  birth: e.detail.value
		})
	  },
	formSubmit:function(e){
		var the =this
		var data=e.detail.value;
		app.util.showLoading('提交中...');
		data.pcd={}
		data.pcd.province=the.data.pcd[0]
		data.pcd.city=the.data.pcd[1]
		data.pcd.district=the.data.pcd[2]
		data.birth = the.data.birth
		console.log(data.birth);
		app.util.post('core/member.set/post/',data);
	},
	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		//console.log(evt);
		app.util[data.func](data.params);
	},
})